package com.chujian.system.core.controller;


import com.chujian.framework.component.def.YForm;
import com.chujian.framework.component.def.YQuery;
import com.chujian.framework.core.base.BaseController;
import com.chujian.framework.core.base.BaseService;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.core.entity.CoreComponent;
import com.chujian.system.core.service.CoreComponentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 组件控制层
 *
 * @author chujian
 * @since 2021-08-25
 */
@RequestMapping("/coreComponent")
@RestController
@Slf4j
public class CoreComponentController extends BaseController<CoreComponent> {

    @Resource
    private CoreComponentService baseService;

    @Override
    public BaseService<CoreComponent> getBaseService() {
        return baseService;
    }

    /**
     * 保存查询组件
     *
     * @param query query定义
     * @return CoreComponent
     */
    @PostMapping("/saveQueryComponent")
    public Result<?> saveQueryComponent(@RequestBody YQuery query) {
        CoreComponent component = baseService.saveQueryComponent(query);
        return okRs(component);
    }

    /**
     * 保存表单组件
     *
     * @param form form
     * @return CoreComponent
     */
    @PostMapping("/saveFormComponent")
    public Result<?> saveFormComponent(@RequestBody YForm form) {
        CoreComponent component = baseService.saveFormComponent(form);
        return okRs(component);
    }


}
